<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ProjectMadaktariMVC.Models.Patient>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    View Patient
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%
        Html.RenderPartial("PatientDetails");

        Response.Write("<div class=\"innerContent\">");

        Response.Write(Model.Episodes.Count == 0 ? "<em>No Episodes</em>" : "Episodes");
        Response.Write("<br />");
        Response.Write("<br />");

        if (Model.Episodes.Count != 0)
        {
            Response.Write("<table class=\"episode_table\">");
            Response.Write("<tr>");
            Response.Write("<th>Date</th>");
            Response.Write("<th>Diagnosis</th>");
            Response.Write("<th>Hospital</th>");
            Response.Write("</tr>");

            using (var db = ProjectMadaktariMVC.Models.DBFactory.CreateContext())
            {
                foreach (ProjectMadaktariMVC.Models.Episode episode in Model.Episodes)
                {
                    if (episode.Id != 0)
                    {
                        Response.Write("<tr class=\"alternate-" + (Model.Episodes.IndexOf(episode) % 2).ToString() + "\">");
                        Response.Write("<td>");

                        var linkText
                            = episode.AdmitDate == null
                            ? "--"
                            : ((DateTime)episode.AdmitDate).ToString("MM/dd/yyyy");

                        Response.Write(Html.ActionLink(linkText, "ViewEpisode", new { EpisodeId = episode.Id, PatientId = Model.Id }));
                        Response.Write("</td>");

                        Response.Write("<td>");
                        Response.Write(episode.GetDiagnosesList(db));
                        Response.Write("</td>");

                        Response.Write("<td>");
                        Response.Write(episode.Hospital.Name);
                        Response.Write("</td>");

                        Response.Write("</tr>");
                    }
                }
            }
            Response.Write("</table>");
        }

        Response.Write("<br />");

        Response.Write(Html.ActionLink("Add New Episode", "AddEpisode", new { id = Model.Id }));

        Response.Write("</div>");
    %>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Header" runat="server">
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="TableSubheader" runat="server">
</asp:Content>
